package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.online.CoolUserOnline;
import cn.da.shuai.cool.system.service.service.ICoolUserOnlineService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 在线用户监控
 */
@RestController
@RequestMapping("/monitor/online")
@Tag(name = "在线用户控制器")
public class CoolUserOnlineController {

    @Autowired
    private ICoolUserOnlineService userOnlineService;

    @GetMapping("/list")
    @Operation(summary = "获取在线用户列表")
    public R<List<CoolUserOnline>> list(CoolUserOnline userOnline) {
        List<CoolUserOnline> list = userOnlineService.selectUserOnlineList(userOnline);
        return R.ok(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取在线用户分页列表")
    public R<Page<CoolUserOnline>> page(CoolUserOnline userOnline, Page<CoolUserOnline> page) {
        Page<CoolUserOnline> list = userOnlineService.selectUserOnlinePage(userOnline, page);
        return R.ok(list);
    }

    @DeleteMapping("/{sessionId}")
    @Operation(summary = "强退用户")
    public R<Void> forceLogout(@PathVariable String sessionId) {
        userOnlineService.forceLogout(sessionId);
        return R.ok();
    }
}